/**
 * @author: HZWei
 * @date: 2025/2/20
 * @desc:
 */
export class ObjectUtil {
  private constructor() {
  }

  static deepCopy(obj: ESObject): ESObject {
    if (typeof obj !== 'object' || obj === null) {
      return obj;
    }
    let copy: ESObject;
    if (Array.isArray(obj)) {
      copy = [];
      for (let i = 0; i < obj.length; i++) {
        copy[i] = ObjectUtil.deepCopy(obj[i]);
      }
    } else {
      copy = {};
      for (let key in obj) {
        if (obj.hasOwnProperty(key)) {
          let keyStr = key + '';
          let suffix = '__ob_'
          if (keyStr.startsWith(suffix)) {
            const newKey = keyStr.substring(suffix.length)
            copy[newKey] = ObjectUtil.deepCopy(obj[key]);
          }else {
            copy[key] = ObjectUtil.deepCopy(obj[key]);
          }


        }
      }
    }
    return copy;
  }
}

